package com.ctcemti.mdm.project.common.excelverifyhandler;

import cn.afterturn.easypoi.excel.entity.result.ExcelVerifyHandlerResult;
import cn.afterturn.easypoi.handler.inter.IExcelVerifyHandler;
import com.ctcemti.mdm.project.sys.dao.InfDictItemMapper;
import com.ctcemti.mdm.project.sys.dao.OrgRoleMapper;
import com.ctcemti.mdm.project.sys.entity.InfDictItem;
import com.ctcemti.mdm.project.sys.entity.OrgRole;

import java.util.ArrayList;
import java.util.List;

public class ExcelVerifyHandlerForRole implements IExcelVerifyHandler<OrgRole> {

    private OrgRoleMapper orgRoleMapper;

    private InfDictItemMapper infDictItemMapper;

    @Override
    public ExcelVerifyHandlerResult verifyHandler(OrgRole orgRole) {

        ExcelVerifyHandlerResult result = new ExcelVerifyHandlerResult();
        List<InfDictItem> infDictItemList = infDictItemMapper.selectInfdictitemByInfdictsortCode("OrgType");
        List<String> temp = new ArrayList<String>();
        for (InfDictItem item:infDictItemList){
            temp.add(item.getName());
        }
        if(!temp.contains(orgRole.getOrgType())){
            result.setMsg("该组织类型不存在");
            result.setSuccess(false);
            return result;
        }
        for (InfDictItem item:infDictItemList){
            if(item.getName().equals(orgRole.getOrgType())){
                orgRole.setOrgType(item.getCode());
            }
        }
        result.setSuccess(true);
        return result;
    }

    public ExcelVerifyHandlerForRole(Object object,InfDictItemMapper infDictItemMapper){
        this.orgRoleMapper = (OrgRoleMapper) object;
        this.infDictItemMapper = infDictItemMapper;

    }
}
